/**
 * 奖励规则变更记录 编辑页
 *
 * 作者 zjb
 * 日期 2024-08-30 09:51:18
 */
layui.use(['jquery','febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#incentiveRewardClauseRuleRecord-edit'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    initFormValue();

    function initFormValue() {
        if (incentiveRewardClauseRuleRecordData) {
            form.val("incentiveRewardClauseRuleRecord-edit-form", {
                "clauseRuleRecordId": incentiveRewardClauseRuleRecordData.clauseRuleRecordId,
                "clauseRuleId": incentiveRewardClauseRuleRecordData.clauseRuleId,
                "changeTime": incentiveRewardClauseRuleRecordData.changeTime,
                "changeType": incentiveRewardClauseRuleRecordData.changeType,
                "beforeJson": incentiveRewardClauseRuleRecordData.beforeJson,
                "afterJson": incentiveRewardClauseRuleRecordData.afterJson,
            });
        }
    }

    form.on('submit(incentiveRewardClauseRuleRecord-edit-form-submit)', function (data) {
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        if (data.clauseRuleRecordId && data.clauseRuleRecordId.length > 0) {
            febs.postArray(ctx + 'incentiveRewardClauseRuleRecord/update', data, function () {
                layer.closeAll();
                febs.alert.success('修改成功');
                febs.reloadPage();
            });
        } else {
            febs.postArray(ctx + 'incentiveRewardClauseRuleRecord', data, function () {
                layer.closeAll();
                febs.alert.success('新增成功');
                $('#febs-incentiveRewardClauseRuleRecord').find('#query').trigger('click');
            });
        }
    }
});